package com.ctgu.redislock01.rabbitmq;

import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @ ClassName RabbitMQConsumer
 * @ Author Alex2
 * @ Date 2025/9/12 15:58
 **/

@Component
@Log4j2
public class RabbitMQConsumer {

    @Autowired
    private StringRedisTemplate redisTemplate;

    private static final String TAG = "ALEX";

    @RabbitListener(queues = RabbitConfig.QUEUE_USER_UPDATE)
    public void handleMessage(String key) {
        try {
            redisTemplate.delete(key);
            log.info("{} : 删除缓存成功", TAG);
        } catch (Exception e) {
            log.error("{} : 删除缓存失败，触发重试", TAG);
            throw new RuntimeException("删除缓存失败，触发重试");
        }
    }
}
